/*
 *  ckr_spec_greater_than_comparison.cpp
 *  ckrSpec
 *
 *  Created by C. Keith Ray on 2006.11.05.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#import "ckr_spec_cpp_specs.h"
#import "ckr_spec_cpp.h"

#include <iostream>
#include <sstream>
#include <vector>
#include <deque>

#include <assert.h>

using namespace std;
using namespace ckr;

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void integral_values_not_greater_than_in_should_be_greater_than_reports_failure();
static void integral_values_greater_than_in_should_be_greater_than_reports_nothing();

static void cstring_values_not_greater_than_in_should_be_greater_than_reports_failure();
static void cstring_values_greater_than_in_should_be_greater_than_reports_nothing();

static void cstring_values_null_in_should_be_greater_than_reports_failure();

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void run_greater_than_comparison_specs()
{
	integral_values_not_greater_than_in_should_be_greater_than_reports_failure();
	integral_values_greater_than_in_should_be_greater_than_reports_nothing();

	cstring_values_not_greater_than_in_should_be_greater_than_reports_failure();
	cstring_values_greater_than_in_should_be_greater_than_reports_nothing();

	cstring_values_null_in_should_be_greater_than_reports_failure();
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(Integral_values_not_greater_in_greater_than_context);

void Integral_values_not_greater_in_greater_than_context::spec()
{
	int int98 = 98;
	int int99 = 99;
	int intAlso99 = 99;

	VALUE( int98 ).SHOULD_BE_GREATER_THAN( int99 ); // failure msg expected
	VALUE( intAlso99 ).SHOULD_BE_GREATER_THAN( int99 ); // failure msg expected		
}

static void integral_values_not_greater_than_in_should_be_greater_than_reports_failure()
{
	Integral_values_not_greater_in_greater_than_context aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	{
		std::string expected1( "int98 (98) should be greater than int99 (99) FAILED in Integral_values_not_greater_in_greater_than_context; line " );
		std::string::size_type foundPos1 = actual.find( expected1, 0 );
		assert( foundPos1 != std::string::npos );
	}
	{
		std::string expected2( "intAlso99 (99) should be greater than int99 (99) FAILED in Integral_values_not_greater_in_greater_than_context; line " );
		std::string::size_type foundPos2 = actual.find( expected2, 0 );
		assert( foundPos2 != std::string::npos );
	}
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(Integral_value_greater_in_greater_than_context);

void Integral_value_greater_in_greater_than_context::spec()
{
	int int98 = 98;
	int int99 = 99;

	VALUE( int99 ).SHOULD_BE_GREATER_THAN( int98 ); // no msg expected
}

static void integral_values_greater_than_in_should_be_greater_than_reports_nothing()
{
	Integral_value_greater_in_greater_than_context aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	std::string expected; //empty

	assert( expected == actual );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(CString_values_not_greater_in_greater_than_context);

void CString_values_not_greater_in_greater_than_context::spec()
{
	char c98[] = "98";
	char* c99 = "99";
	char cAlso99[] = "99";

// if you use VALUE instead of CSTRING_VALUE, you will get error msgs from
// the compiler saying something like
// "no matching function for the call to 'ckr::AssertableValue<char [3]>
// ::should_be_greater_than_impl(char*&,const char [4])'"

	CSTRING_VALUE( c98 ).SHOULD_BE_GREATER_THAN( c99 ); // failure msg expected
	CSTRING_VALUE( cAlso99 ).SHOULD_BE_GREATER_THAN( c99 ); // failure msg expected		
}

static void cstring_values_not_greater_than_in_should_be_greater_than_reports_failure()
{
	CString_values_not_greater_in_greater_than_context aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	{
		std::string expected1( "c98 (98) should be greater than c99 (99) FAILED in CString_values_not_greater_in_greater_than_context; line " );
		std::string::size_type foundPos1 = actual.find( expected1, 0 );
		assert( foundPos1 != std::string::npos );
	}
	{
		std::string expected2( "cAlso99 (99) should be greater than c99 (99) FAILED in CString_values_not_greater_in_greater_than_context; line " );
		std::string::size_type foundPos2 = actual.find( expected2, 0 );
		assert( foundPos2 != std::string::npos );
	}
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(CString_value_greater_in_greater_than_context);

void CString_value_greater_in_greater_than_context::spec()
{
	char c98[] = "98";
	char* c99 = "99";

	CSTRING_VALUE( c99 ).SHOULD_BE_GREATER_THAN( c98 ); // no msg expected
}

static void cstring_values_greater_than_in_should_be_greater_than_reports_nothing()
{
	CString_value_greater_in_greater_than_context aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	std::string expected; //empty

	assert( expected == actual );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(CStrings_null_in_greater_than_context);

void CStrings_null_in_greater_than_context::spec()
{
	char c98[] = "98";
	char* strNull = NULL;
	char* alsoNull = NULL;

	CSTRING_VALUE( strNull ).SHOULD_BE_GREATER_THAN( c98 ); // fail msg expected
	CSTRING_VALUE( c98 ).SHOULD_BE_GREATER_THAN( strNull ); // fail msg expected
	CSTRING_VALUE( alsoNull ).SHOULD_BE_GREATER_THAN( strNull ); // fail msg expected
}

static void cstring_values_null_in_should_be_greater_than_reports_failure()
{
	CStrings_null_in_greater_than_context aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	{
		std::string expected1( "strNull ((NULL POINTER)) should be greater than c98 (98) FAILED in CStrings_null_in_greater_than_context; line " );
		std::string::size_type foundPos1 = actual.find( expected1, 0 );
		assert( foundPos1 != std::string::npos );
	}
	{
		std::string expected2( "c98 (98) should be greater than strNull ((NULL POINTER)) FAILED in CStrings_null_in_greater_than_context; line " );
		std::string::size_type foundPos2 = actual.find( expected2, 0 );
		assert( foundPos2 != std::string::npos );
	}
	{
		std::string expected2( "alsoNull ((NULL POINTER)) should be greater than strNull ((NULL POINTER)) FAILED in CStrings_null_in_greater_than_context; line " );
		std::string::size_type foundPos2 = actual.find( expected2, 0 );
		assert( foundPos2 != std::string::npos );
	}
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
